load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
load("//bazel:canisters.bzl", "rust_canister")
load("//bazel:defs.bzl", "rust_ic_test")

package(default_visibility = ["//visibility:public"])

rust_library(
    name = "btc_checker_lib",
    srcs = glob(["lib/**"]),
    crate_name = "ic_btc_checker",
    deps = [
        # Keep sorted.
        "@crate_index//:bitcoin",
        "@crate_index//:candid",
        "@crate_index//:ic-btc-interface",
        "@crate_index//:serde",
    ],
)

rust_test(
    name = "unit_tests",
    crate = ":btc_checker_lib",
)

rust_test(
    name = "canister_tests",
    crate = ":_wasm_btc_checker_canister",
    data = ["btc_checker_canister.did"],
    env = {
        "CARGO_MANIFEST_DIR": "rs/bitcoin/checker",
    },
    deps = [
        # Keep sorted.
        "@crate_index//:candid_parser",
        "@crate_index//:ic-btc-interface",
        "@crate_index//:proptest",
        "@crate_index//:scraper",
        "@crate_index//:tokio",
    ],
)

rust_canister(
    name = "btc_checker_canister",
    srcs = glob(["src/**"]),
    compile_data = [
        "templates/dashboard.html",
    ],
    service_file = "btc_checker_canister.did",
    deps = [
        # Keep sorted.
        ":btc_checker_lib",
        "//packages/ic-http-types",
        "@crate_index//:askama",
        "@crate_index//:base64",
        "@crate_index//:bitcoin",
        "@crate_index//:candid",
        "@crate_index//:candid_parser",
        "@crate_index//:ciborium",
        "@crate_index//:futures",
        "@crate_index//:hex",
        "@crate_index//:ic-btc-interface",
        "@crate_index//:ic-canister-log",
        "@crate_index//:ic-cdk",
        "@crate_index//:ic-management-canister-types",
        "@crate_index//:ic-metrics-encoder",
        "@crate_index//:ic-stable-structures",
        "@crate_index//:serde",
        "@crate_index//:serde_json",
        "@crate_index//:time",
        "@crate_index//:url",
    ],
)

rust_ic_test(
    name = "integration_tests",
    srcs = ["tests/tests.rs"],
    data = [
        ":btc_checker_canister",
        "//rs/universal_canister/impl:universal_canister.wasm.gz",
    ],
    env = {
        "CARGO_MANIFEST_DIR": "rs/bitcoin/checker",
        "IC_BTC_CHECKER_CANISTER_WASM_PATH": "$(rootpath :btc_checker_canister)",
        "POCKET_IC_BIN": "$(rootpath //:pocket-ic-server)",
        "UNIVERSAL_CANISTER_WASM_PATH": "$(rootpath //rs/universal_canister/impl:universal_canister.wasm.gz)",
    },
    deps = [
        # Keep sorted.
        ":btc_checker_lib",
        "//:pocket-ic-server",
        "//packages/ic-http-types",
        "//packages/ic-metrics-assert:ic-metrics-assert_pocket_ic",
        "//packages/pocket-ic",
        "//rs/test_utilities/load_wasm",
        "//rs/types/base_types",
        "//rs/types/types",
        "//rs/universal_canister/lib",
        "@crate_index//:candid",
        "@crate_index//:ic-btc-interface",
        "@crate_index//:ic-cdk",
        "@crate_index//:ic-management-canister-types",
        "@crate_index//:regex",
    ],
)
